package org.easy.tool.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.easy.tool.common.TimeUtil;
import org.easy.tool.entity.Problem;
import org.easy.tool.entity.Type;
import org.easy.tool.mapper.TypeMapper;
import org.easy.tool.service.IType;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Valley
 * @since 2023-08-25 14:20:43
 */
@Service
public class TypeService extends ServiceImpl<TypeMapper, Type> implements IType {

    @Autowired
    TypeMapper typeMapper;

    @Override
    public Type getTypeById(String typeId) {
        LambdaQueryWrapper<Type> lambda = new LambdaQueryWrapper<>();
        lambda.eq(Type::getId, typeId);
        return getOne(lambda);
    }

    @Override
    public String addType(Type type) {
        type.setCreateTime(TimeUtil.now());
        type.setUpdateTime(TimeUtil.now());
        save(type);
        return type.getId();
    }

    @Override
    public List<Type> getTypeByTitle(String title) {
        LambdaQueryWrapper<Type> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Type::getTitle, title);
        return typeMapper.selectList(wrapper);
    }

}
